<?php

namespace App\Models\Activity;

use App\Models\BaseModel;
use App\Models\Traits\KfSoftDeletes;
use App\Models\Traits\KfUid;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class ActivityShopJoinFeedbackModel extends BaseModel
{
    use HasFactory, KfUid, KfSoftDeletes;

    protected $table = "activity_shop_join_feedback";


    /**
     * 获取门店回传详情
     * @param int $activityId
     * @param int $shopId
     * @return array
     */
    public static function getActivityShopInfo(int $activityId, int $shopId): array
    {
        $info = ["feedbackStatus" => 0];
        $res  = ActivityShopJoinModel::getAppliedStatus($activityId, $shopId, 0, 0, ActivityShopJoinModel::STATUS_3);
        if ($res) {
            self::query()
                ->where('shopJoinId', $res->id)
                ->where('activityId', $activityId)
                ->get()
                ->map(
                    function ($item) use (&$info) {
                        $info["feedbackStatus"] = 1;
                        if ($item->key) {
                            return $info[$item->key] = $item->type == 'array' ? json_decode($item->value, true) : $item->value;
                        }
                    }
                );
        }
        return $info;
    }
}
